package cn.com.chengmandian.bike.service.impl;

import cn.com.chengmandian.bike.model.EbRechargeActivity;
import cn.com.chengmandian.bike.model.EbRechargeRecord;
import cn.com.chengmandian.bike.mapper.EbRechargeRecordMapper;
import cn.com.chengmandian.bike.service.IEbRechargeRecordService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2022-12-06
 */
@Service
public class EbRechargeRecordServiceImpl extends ServiceImpl<EbRechargeRecordMapper, EbRechargeRecord> implements IEbRechargeRecordService {

    @Override
    public void createRecord(Integer payId,Integer areaId, Integer memberId, EbRechargeActivity ebRechargeActivity, BigDecimal chargeMoney) {
        EbRechargeRecord ebRechargeRecord = new EbRechargeRecord();
        ebRechargeRecord.setAreaId(areaId);
        ebRechargeRecord.setMemberId(memberId);
        if(ObjectUtil.isNotNull(ebRechargeActivity)) {
            ebRechargeRecord.setActivityId(ebRechargeActivity.getId());
            ebRechargeRecord.setActivityName(ebRechargeActivity.getName());
            ebRechargeRecord.setGiftMoney(ebRechargeActivity.getGiftMoney());
        }
        ebRechargeRecord.setChargeMoney(chargeMoney);
        ebRechargeRecord.setPayId(payId);
        ebRechargeRecord.setCreateTime(DateUtil.date());
        this.save(ebRechargeRecord);
    }
}
